package com.zygh.policeasset.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.EachTypeImages;
import com.zygh.policeasset.service.EachTypeImagesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/eachTypeImages"})
@Api(tags = {"其他类型图片上传"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/EachTypeImagesController.class */
public class EachTypeImagesController {
    @Autowired
    EachTypeImagesService eachTypeImagesService;

    @RequestMapping(value = {"/findbyTypeIdAndType"}, method = {RequestMethod.GET})
    @ApiOperation("根据图片类型的主键和类型查询")
    public Object findbyTypeIdAndType(@RequestParam Integer typeId, @RequestParam String type) {
        return this.eachTypeImagesService.findbyTypeIdAndType(typeId, type);
    }

    @RequestMapping(value = {"/whenUpateImage"}, method = {RequestMethod.POST})
    @ApiOperation("修改时添加图片")
    public Object whenUpateImage(EachTypeImages eachTypeImages) {
        return this.eachTypeImagesService.whenUpateImage(eachTypeImages);
    }

    @RequestMapping(value = {"/whenAddImage"}, method = {RequestMethod.POST})
    @ApiOperation("添加时添加图片")
    public Object whenAddImage(EachTypeImages eachTypeImages) {
        return this.eachTypeImagesService.whenAddImage(eachTypeImages);
    }

    @RequestMapping(value = {"/remove"}, method = {RequestMethod.POST})
    @ApiOperation("根据图片表id删除图片")
    public Object remove(@RequestBody JSONObject json) {
        if (StrUtil.isEmpty(String.valueOf(json.getInteger("id")))) {
            return new CommonResult().validateFailed("主键id不能为空");
        }
        if (this.eachTypeImagesService.delete(json.getInteger("id")).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除错误");
    }
}